<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/5.4.5/css/swiper.min.css"
    />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/5.4.5/js/swiper.js"></script>
  </head>
  <body>
    <!-- 
    watch 数据是新的的dom还是修改之前的
  -->
    <div id="app">
      <banner></banner>
      <banner></banner>
    </div>

    <template id="banner">
      <div>
        <div class="swiper">
          <div class="swiper-wrapper">
            <div class="swiper-slide" v-for="item,index in imgs" :key="index">
              <img :src="item" alt="">
            </div>
            
          </div>
          <!-- 如果需要导航按钮 -->
          <div class="swiper-button-prev"></div>
          <div class="swiper-button-next"></div>
        </div>
      </div>
    </template>

    <script>
      Vue.component("banner", {
        data() {
          return {
            imgs: [
              "https://img0.baidu.com/it/u=89550981,876704971&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=500",
              "https://img1.baidu.com/it/u=1225256868,1928975993&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=500",
              "https://img0.baidu.com/it/u=4271931651,3023717257&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=500"
            ]
          }
        },
        template: "#banner",
        mounted() {
          var mySwiper = new Swiper(".swiper", {
            loop: true, // 循环模式选项
            // 如果需要前进后退按钮
            navigation: {
              nextEl: ".swiper-button-next",
              prevEl: ".swiper-button-prev",
            },
          });
        },
      });
      new Vue({
        el: "#app",
      });
    </script>
  </body>
</html>
